//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "NullDomain.h"
using namespace Cephei::QL::Math;
#include <gen/QL/Math/Domain.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::CNullDomain::CNullDomain (boost::shared_ptr<QuantLib::NullDomain>& childNative, Object^ owner) : CDomain(CNullDomain::typeid)
{
#ifdef HANDLE
	_phNullDomain = NULL;
#endif
	_ppNullDomain = &childNative;
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppNullDomain));
}
Cephei::QL::Math::CNullDomain::CNullDomain (QuantLib::NullDomain& childNative, Object^ owner) : CDomain(CNullDomain::typeid)
{
#ifdef HANDLE
	_phNullDomain = NULL;
#endif
	_ppNullDomain = new boost::shared_ptr<QuantLib::NullDomain> (&childNative);
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppNullDomain));
    _NullDomainOwner = owner;
    _DomainOwner = owner;
}

Cephei::QL::Math::CNullDomain::CNullDomain (CNullDomain^ copy) : CDomain(CNullDomain::typeid)
{
#ifdef HANDLE
	_phNullDomain = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppNullDomain = new boost::shared_ptr<QuantLib::NullDomain> (copy->GetShared());
        _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppNullDomain));
    }
}
Cephei::QL::Math::CNullDomain::CNullDomain (PLATFORM::Type^ t) : CDomain(CNullDomain::typeid)
{
#ifdef HANDLE
	_phNullDomain = NULL;
#endif
	if (!t->IsSubclassOf(CNullDomain::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::CNullDomain::CNullDomain (QuantLib::Handle<QuantLib::NullDomain>& childNative, Object^ owner)  : CDomain(CNullDomain::typeid)
{
	_phNullDomain = &childNative;
	_ppNullDomain = &static_cast<boost::shared_ptr<QuantLib::NullDomain>>(childNative.currentLink());
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppNullDomain));
    _NullDomainOwner = owner;
}
Cephei::QL::Math::CNullDomain::CNullDomain (QuantLib::Handle<QuantLib::NullDomain> childNative)  : CDomain(CNullDomain::typeid)
{
	_phNullDomain = &childNative;
	_ppNullDomain = &static_cast<boost::shared_ptr<QuantLib::NullDomain>>(childNative.currentLink());
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppNullDomain));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::CNullDomain::CNullDomain (QuantLib::NullDomain childNative)  : CDomain(CNullDomain::typeid)
{
#ifdef HANDLE
	_phNullDomain = NULL;
#endif
	_ppNullDomain = new boost::shared_ptr<QuantLib::NullDomain> (new QuantLib::NullDomain (childNative));
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppNullDomain));
}
#endif

Cephei::QL::Math::CNullDomain::~CNullDomain ()
{
    if (_ppNullDomain != NULL)
    {
	    delete _ppNullDomain;
        _ppNullDomain = NULL;
    }
}
Cephei::QL::Math::CNullDomain::!CNullDomain ()
{
    if (_ppNullDomain != NULL)
    {
	    delete _ppNullDomain;
    }
}
QuantLib::NullDomain& Cephei::QL::Math::CNullDomain::GetReference ()
{
    if (_ppNullDomain == NULL) throw REFNEW NativeNullException ();
	return **_ppNullDomain;
}
boost::shared_ptr<QuantLib::NullDomain>& Cephei::QL::Math::CNullDomain::GetShared ()
{
    if (_ppNullDomain == NULL) throw REFNEW NativeNullException ();
	return *_ppNullDomain;
}
QuantLib::NullDomain* Cephei::QL::Math::CNullDomain::GetPointer ()
{
    if (_ppNullDomain == NULL) throw REFNEW NativeNullException ();
	return &**_ppNullDomain;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::NullDomain>& Cephei::QL::Math::CNullDomain::GetHandle ()
{
	if (_phNullDomain == NULL)
	{
		_phNullDomain = new Handle<QuantLib::NullDomain> (*_ppNullDomain);
	}
	return *_phNullDomain;
}
#endif
bool Cephei::QL::Math::CNullDomain::HasNative () 
{
	return (_ppNullDomain != NULL);
}

Boolean Cephei::QL::Math::CNullDomain::Includes (Double prm1, Double prm2)
{
    try
    {
        QuantLib::Real _prm1 = (QuantLib::Real)ValueHelper::Convert (prm1); //a
        QuantLib::Real _prm2 = (QuantLib::Real)ValueHelper::Convert (prm2); //a
    	bool _rv = (bool)(*_ppNullDomain)->includes ( _prm1,  _prm2 );   
        Boolean _nrv = (Boolean)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

